/**
 * @ClassName:
 * @Description:
 */
package com.neusoft.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.core.mapper.BaseMapper;
import com.neusoft.base.BaseServiceImpl;
import com.neusoft.config.Pagination;
import com.neusoft.mapper.CarMapper;
import com.neusoft.model.OrderSearch;
import com.neusoft.po.CarItemRel;
import com.neusoft.service.CarService;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;

/**
 * 购物车业务逻辑
 *
 * @author Lucifer
 * @since 2021/5/15 23:18
 */
@Service
public class CarServiceImpl extends BaseServiceImpl<CarItemRel> implements CarService {

    @Resource
    private CarMapper carMapper;

    @Override
    public BaseMapper<CarItemRel> getBaseDao() {
        return carMapper;
    }

    @Override
    public Integer save(CarItemRel entity) {
        Integer id = entity.getId();
        if (null == id) {
            insert(entity);
            id = entity.getId();
        } else {
            updateById(entity);
        }
        return id;
    }

    @Override
    @Pagination
    public Object page(OrderSearch orderSearch) {
        return carMapper.list(orderSearch);
    }

    @Override
    public Integer remove(Integer[] ids, Integer user_id) {
        return carMapper.delete(new QueryWrapper<CarItemRel>().in("item_id", ids).eq("user_id", user_id));
    }

}
